<?php
require dirname(__FILE__) . '/checkuser.php';
require dirname(dirname(__FILE__)) . '/include/conf.php';
require dirname(dirname(__FILE__)) . '/include/database.php';

$re = 'fail';
$bet_id = '';
$bet_money = '';

$db = db_touzhu();
$nowtime = date('Y-m-d H:i:s', time() - 60 * 5);
$sql = "select id, bet_id, bet_money, add_time, status from auto_bet where status=0 and add_time>='{$nowtime}' order by id desc limit 1";
$re_db = $db->query($sql);
if (isset($re_db[0])){
	$re = 'succ';
	$bet_id = $re_db[0]['bet_id'];
	$bet_money = $re_db[0]['bet_money'];
	
	$sql_up = "update auto_bet set status=1 where id={$re_db[0]['id']}";
	$db->query($sql_up);
}

$result = array(
	'error' => $re,
	'betid' => $bet_id,
	'betmoney' => $bet_money
);
exit(json_encode($result));
